/**
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
*
* BaseProcessDocumentGroupService
* 文档配置组表
*
* 修改纪录
* 2021-07-28 版本：1.0 chengengwei 创建。
* @version 版本：1.0
* @author 作者：chengengwei
* 创建日期：2021-07-28
*/
package com.topscomm.base.service.impl;

import com.topscomm.base.pojo.BaseProcessDocumentInfoEntity;
import com.topscomm.base.service.IBaseProcessDocumentGroupService;
import com.topscomm.base.service.IBaseProcessDocumentInfoService;
import com.topscomm.base.service.impl.auto.BaseProcessDocumentGroupServiceAuto;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.tap.common.DatacodeCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service(value = "baseProcessDocumentGroupService")
@Scope(value = "singleton")
public class BaseProcessDocumentGroupService extends BaseProcessDocumentGroupServiceAuto implements IBaseProcessDocumentGroupService {

    @Autowired
    private IBaseProcessDocumentInfoService baseProcessDocumentInfoService;

    /**
     * @author: chengengwei
     * @date: 2021-07-28
     * @param mapRow
     * @description:设置字段显示值
     * @modify:
     */
    @Override
    public void setDispFields(Map<String, Object> mapRow, DatacodeCache datacodeCache) {
        super.setDispFields(mapRow, datacodeCache);
        String temp;
        if (mapRow.get("role") != null) {
            temp = mapRow.get("role").toString();
            mapRow.put("disprole", datacodeCache.getValueDynamic("CboRole", temp, "id", "name"));
        }
    }

    /**
     * @author: chengengwei
     * @date: 2021-07-28
     * @description: 删除组信息时同时删除关联的流程文档信息
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteGroupAndDocInfo(Map<String, Object> paraMap) {
        paraMap = BaseUtil.decodeSecureMap(paraMap);
        String ids = ConvertUtil.convertToString(paraMap.get("ids"));
        StringBufferProxy whereSql = new StringBufferProxy();
        whereSql.appendSingle("id in ({0})", ids);
        this.deleteByWhere(whereSql.toString());
        whereSql.clear();
        // 查询关联的检查项记录并删除
        whereSql.appendSingle("{0} in (select code from BaseCurrencyCheckItemGroup where id in ({1}))",
                BaseProcessDocumentInfoEntity.FieldCategory, ids);
        this.baseProcessDocumentInfoService.deleteByWhere(whereSql.toString());
    }
}
